package com.runmi.webchat.aftersale.common.page;

import java.io.Serializable;

public class PageModel implements Serializable{

	private Integer pageSize=10;//每页大小
	private Integer cpage=1;
	private Integer totalCount;
	private Integer totalPage;
	private Integer nextPage;
	private Integer prePage;
	private Integer pageFirst;
	private Integer dispPageCount = 10;
	private Boolean isAjax=false;
	private Integer offset;
	
	
	
	
	public void setDispPageCount(Integer dispPageCount) {
		this.dispPageCount = dispPageCount;
		Init();
	}
	public Integer getDispPageCount() {
		return dispPageCount;
	}
	public Integer getOffset() {
		return offset;
	}
	public void setOffset(Integer offset) {
		this.offset = offset;
	}
	public Boolean getIsAjax() {
		return isAjax;
	}
	public void setIsAjax(Boolean isAjax) {
		this.isAjax = isAjax;
	}
	/**
	 * 每页数据多少条
	 * @return
	 */
	public Integer getPageSize() {	
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {		
		this.pageSize = pageSize;
		Init();
	}
	/**
	 * 当前页
	 * @return
	 */
	public Integer getCpage() {
		
		return cpage;
	}
	public void setCpage(Integer cpage) {	
		this.cpage = cpage;
		Init();
	}
	/**
	 * 总记录数
	 * @return
	 */
	public Integer getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
		Init();
	}
	/**
	 * 总页数
	 * @return
	 */
	public Integer getTotalPage() {		 
		return totalPage;
	}
	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}
	/**
	 * 下一页
	 * @return
	 */
	public Integer getNextPage() {		 
		return nextPage;
	}
	public void setNextPage(Integer nextPage) {
		this.nextPage = nextPage;
	}
	/**
	 * 前一页
	 * @return
	 */
	public Integer getPrePage() {
		return prePage;
	}
	public void setPrePage(Integer prePage) {
		this.prePage = prePage;
	}
	/**
	 * 当前页码的第一个
	 * @return
	 */
	public Integer getPageFirst() {
		return pageFirst;
	}
	
	public void setPageFirst(Integer pageFirst) {
		this.pageFirst = pageFirst;
	}
	
	/**
	 * 重新计算分页数据
	 */
	private void Init(){
		
		if(null==cpage || cpage==0){
			cpage=1;
		}
		if(null==pageSize || pageSize==0){
			pageSize=10;
		}
		
		if(null==dispPageCount || dispPageCount==0){
			dispPageCount=10;
		}
		totalCount=totalCount==null?0:totalCount;

			
		/**计算总页数**/
        if (pageSize > 0 && totalCount > 0)
        {
        	totalPage = totalCount / pageSize;
            int count = totalCount % pageSize;
            if (count > 0)
            {
            	totalPage = totalPage + 1;
            }
        }else{
        	totalPage=0;
        }
		
		/**计算当下一页**/
		if((cpage+1)>totalPage)
        {
			 nextPage= totalPage;
        }
        else
        {
       	 	nextPage= cpage + 1;
        }
		
		/**计算前页**/
		if ((cpage - 1) < 1)
        {
			prePage= 1;
        }
        else
        {
        	prePage= cpage - 1;
        }
		
				
		/**计算首页**/
		if (cpage > dispPageCount)
        {
            int num = (cpage % dispPageCount);
            if (num > 0)
            {
            	pageFirst = ((cpage / dispPageCount) * dispPageCount) + 1;
            }
            else
            {
            	pageFirst = (((cpage / dispPageCount) - 1) * dispPageCount) + 1;
            }
        }else{
        	pageFirst=1;
        }	
		offset = (cpage - 1) * pageSize;  
	}
}
